﻿<?php
class DocmanAction extends CommonAction {

	// 框架首页
	public function index() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();

			//读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			foreach ( $list as $key => $module ) {
				if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
					//设置模块访问权限
					$module ['access'] = 1;
					$menu [$key] = $module;
				}
			}

			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
			//dump($menu);
			$this->assign ( 'menu', $menu );

			$this->assign('test', 'aaa');
		}
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );

		// $this->assign('dirlist', $this->dirlist('D:/xampp/htdocs/google_code/ellacms/public/files/'));
		$this->assign('dirlist', $this->dirlist('E:/xampp/htdocs/google_code/dwz_thinkphp/public/files/'));

		$this->display ();
	}


	function ac(){
//		print_r($_REQUEST);
//		echo '<hr>';
//		print_r($_SESSION);

		$ac = $_REQUEST['ac'];
		$file = $_REQUEST['file'];

		$curr_location = $_REQUEST['c_l'];

		if ( $ac == 'copy' ){
			$_SESSION['copy'] = FILES_PATH.$file;
			$_SESSION['next_ac'] = 'copy';
		}


		else if ( $ac == 'paste'){
			//if choose folder
			if ( $curr_location == '/'){
				$curr_location = $file.'/';
			}
			
			//get the copy file name
			$copy_arr = explode('/', $_SESSION['copy']);
			$filename = array_pop($copy_arr);
//			echo $filename;
			
			if( $_SESSION['next_ac'] == 'copy'){
//				copy($_SESSION['copy'], $curr_location);
				copy($_SESSION['copy'], FILES_PATH.$curr_location.$filename);
//				copy('../Public/files/html/check/hello.html', )
			}
			else if ( $_SESSION['next_ac'] == 'cut' ){
				copy($_SESSION['copy'], FILES_PATH.$curr_location.$filename);
				unlink($_SESSION['copy']);
			}
		}

		else if ( $ac == 'cut'){
//			rename($_SESSION['cut'], FILES_PATH.$file);
			$_SESSION['copy'] = FILES_PATH.$file;
			$_SESSION['next_ac'] = 'cut';
		}

		else if( $ac == 'del'){
			//			echo '__APP__';
			unlink(FILES_PATH.$file);
			//			echo FILES_PATH.$file;
		}

		//		echo $ac.' '.$file;
		//		echo $ac;
		$this->success('success!');
	}



}
?>